/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ROOM_H
#define ROOM_H

#include <string>
#include <deque>

namespace Chronos {

class MudObject;
class MudPlayer;
class MudMobile;

class ObjectVisitor {
public:
    virtual ~ObjectVisitor() {}
    virtual bool handle(MudObject* object) = 0;
};


class Room {
public:
    Room(const std::string& name_, const std::string& descr);
    virtual ~Room();
    static unsigned int count;

    const std::string& getName() const;
    const std::string& getShortDescription() const;
    const std::string& getLongDescription() const;

    void addPlayer(MudPlayer& player, const std::string& msg = "");
    void removePlayer(MudPlayer& player, const std::string& msg = "");
	MudPlayer* getFirstPlayer() const;

    void addObject(MudObject* object);
    void removeObject(MudObject* object);
    MudObject* findObject(const std::string& name) const;
    void visitObjects(ObjectVisitor& visitor);
    
    virtual void showText(const std::string& text);
    virtual void showText(const std::string& text, const MudMobile& mobile1);
    virtual void showText(const std::string& text, const MudMobile& mobile1, const MudMobile& mobile2);
private:
    void generateDescription() const;
    void notifyRoomListeners(MudMobile& mobile);

    std::string name;
    std::string description;
	mutable std::string longDescription;
	mutable std::string shortDescription;

    typedef std::deque<MudPlayer*> Players;
    typedef Players::const_iterator PlayersConstIter;
    typedef Players::iterator PlayersIter;
    Players players;

    typedef std::deque<MudObject*> Objects;
    typedef Objects::const_iterator ObjectsConstIter;
    typedef Objects::iterator ObjectsIter;
    Objects objects;

    Room(const Room&);
    Room& operator=(const Room&);
};

}

#endif

